package com.relsell.view.phone;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.MediaController;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.VideoView;

import com.relsell.tmcprototype.R;

public class PlayVideo extends Activity {
	private VideoView mVideoView;
	private ProgressBar mProgressBar;
	private LinearLayout mProgressBarLayout;
	private String mDataSourceUri;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);  
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,   
                             WindowManager.LayoutParams.FLAG_FULLSCREEN);  
		Intent i = getIntent();
		if (i != null) {
			mDataSourceUri = i.getStringExtra("datasource");
		}
		setContentView(R.layout.videoview_main);
		
		mVideoView = (VideoView)findViewById(R.id.videoView1);
		mProgressBar = (ProgressBar)findViewById(R.id.progressBar1);
		mProgressBarLayout = (LinearLayout)findViewById(R.id.progressBarLayout);
		//setupActionBar();
		playVideoWithLocalDataSource();
	}
	/**
	 * setCustomize actionBar Via this method
	 */
	private void setupActionBar() {
	    ActionBar actionBar = getActionBar();
	    actionBar.setDisplayShowTitleEnabled(false);
	    actionBar.setDisplayUseLogoEnabled(false);
	    actionBar.setDisplayHomeAsUpEnabled(false);
	    actionBar.setDisplayShowCustomEnabled(true);
	    actionBar.setDisplayShowHomeEnabled(true);
	    
	    View customNav = LayoutInflater.from(this).inflate(R.layout.cutomizedactionbar, null); // layout which contains your button.
	    TextView tv=(TextView)customNav.findViewById(R.id.textView1);
	    tv.setText(Html.fromHtml(getString(R.string.actionbar_name))); 
	    actionBar.setCustomView(customNav);
	}
	private void playVideoWithLocalDataSource () {
		MediaController mc = new MediaController(this);
		mVideoView.setMediaController(mc);
		mVideoView.setBackgroundColor(Color.WHITE);
		mVideoView.setVideoURI(Uri.parse("http://khottal.com/ankur/guitar.3gp"));
        mVideoView.setOnPreparedListener(new OnPreparedListener() {
			
			@Override
			public void onPrepared(MediaPlayer mp) {
				mProgressBarLayout.setVisibility(View.GONE);
				mVideoView.setBackgroundColor(Color.TRANSPARENT);
				mVideoView.setVisibility(View.VISIBLE);
				
			}
		});
		mVideoView.start();
	}

}
